#include <iostream>
#include <cmath>
#include <string>
#include <sstream>

bool isPrime(int num) {
    if (num <= 1) return false;
    for (int i = 2; i <= std::sqrt(num); ++i) {
        if (num % i == 0) return false;
    }
    return true;
}

int findNearestPrime(int num) {
    int lower = num - 1;
    int upper = num + 1;

    while (!isPrime(lower) && !isPrime(upper)) {
        --lower;
        ++upper;
    }

    if (std::abs(lower - num) <= std::abs(upper - num))
        return lower;
    else
        return upper;
}

bool hasDigits(const std::string& str) {
    for (char c : str) {
        if (std::isdigit(c)) return true;
    }
    return false;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::istringstream iss(input);
    std::string word;
    std::string x = "";

    while (iss >> word) {
        if (word == "one") x += "1";
        else if (word == "two") x += "2";
        else if (word == "three") x += "3";
        else if (word == "four") x += "4";
        else if (word == "five") x += "5";
        else if (word == "six") x += "6";
        else if (word == "seven") x += "7";
        else if (word == "eight") x += "8";
        else if (word == "nine") x += "9";
        else if (word == "zero") x += "0";
    }

    if (hasDigits(input)) {
        std::cout << "Wrong input" << std::endl;
    } else {
        int number = std::stoi(x);
        int nearestPrime = findNearestPrime(number);
        std::cout << nearestPrime << std::endl;
    }

    return 0;
}